var api = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        page: 1,
        u_id: '',
        follow_id: '',
        attentionUser: [],
        isSelf: !0
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        var a = this, page = a.data.page;
        a.data.u_id = options.u_id;
        if (options.follow_id && options.u_id){
            a.data.follow_id = options.follow_id;
            a.initLoad(options.u_id, options.follow_id, page, !1);
        }else{
            a.initLoad(options.u_id, options.u_id, page, !0);
        }
    },

    initLoad: function (u_id, follow_id, page, isSelf){
        var a = this;
        wx.showLoading({ title: '加载中...' });
        wx.request({
            url: api.globalData.Api + '/followList',
            data: {
                u_id: u_id,
                follow_id: follow_id,
                page: page
            },
            method: 'GET',
            dataType: 'json',
            success: function (res) {
                if (res.data.status == 1) {
                    if(page > 1){
                        var d = res.data.data.data;
                        if (d.length == 0) {
                            wx.showToast({
                                title: '已全部加载完成',
                            });
                        } else {
                            a.setData({
                                attentionUser: a.data.attentionUser.concat(d),
                                page: page
                            }), wx.hideLoading();
                        }
                    } else {
                        a.data.attentionUser = res.data.data.data;
                        a.setData({
                            attentionUser: res.data.data.data,
                            isSelf: isSelf
                        }), wx.hideLoading();
                    }
                }
            }
        })
    },

    toggleAttention: function(f){
        var a = this, o = a.data.attentionUser, c = f.currentTarget.dataset, u2_id = c.u2_id, i = c.index, s = c.su_state;
        if (a.data.u_id == u2_id){
            wx.showModal({
                title: '提示',
                content: '不能自己关注自己',
                showCancel: false
            });
        }else{
            wx.request({
                url: api.globalData.Api + '/followUser',
                data: {
                    u1_id: a.data.u_id,
                    u2_id: u2_id
                },
                method: 'GET',
                dataType: 'json',
                success: function (res) {
                    if (res.data.status == 1) {
                        if (s == 1) {
                            wx.showToast({ title: '取消关注成功' }), o[i].state = 0;
                            a.setData({ attentionUser: o })
                        } else {
                            wx.showToast({ title: '关注成功' }), o[i].state = 1;
                            a.setData({ attentionUser: o });
                        }
                    }
                }
            })
        }
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {
        var a = this, u_id = a.data.u_id, page = a.data.page + 1;
        if (a.data.follow_id && u_id) {
            a.initLoad(u_id, a.data.follow_id, page);
        } else {
            a.initLoad(u_id, u_id, page);
        }
    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})